<?php

namespace App\Admin\Controllers;

use App\Models\Customer;
use Encore\Admin\Controllers\AdminController as Controller;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CustomerController extends Controller
{
    protected $title = "用户管理";

    protected function grid()
    {
        $grid = new Grid(new Customer);

        $grid->filter(function ($filter) {
            $filter->like('username', '用户名');
            $filter->like('mobile', '手机号');
        });
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->disableRowSelector();

        $grid->id('用户 ID');
        $grid->username('用户名');
        $grid->mobile('手机号');
        $grid->verify_at('认证时间');
        $grid->column('pocket.amount', '钱包余额');
        $grid->status('状态')->switch([
            'on' => ['value' => 1, 'text' => '正常', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
        ]);
        $grid->created_at('注册时间');
        $grid->updated_at('最后登录时间');

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Customer::findOrFail($id));

        $show->id('用户 ID');
        $show->username('用户名');
        $show->mobile('手机号');
        $show->verify_at('认证时间');
        $show->status('状态')->switch([
            'on' => ['value' => 1, 'text' => '正常', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
        ]);
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    protected function form()
    {
        $form = new Form(new Customer);

        $form->text('username', 'Username');
        $form->mobile('mobile', 'Mobile');
        $form->password('password', 'Password');
        $form->date('verify_at', 'Verify at')->default(date('Y-m-d'));
        $form->switch('status', 'Status')->default(1);

        return $form;
    }
}
